package com.xt.partjobback.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xt.partjobback.constant.CommonConstant;
import com.xt.partjobback.constant.ResultDTO;
import com.xt.partjobback.dto.CollectDto;
import com.xt.partjobback.entity.Collect;
import com.xt.partjobback.service.CollectService;
import com.xt.partjobback.utils.TokenUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping(CommonConstant.API_URI_VERSION_V1+"/collect")
public class CollectController {

    @Autowired
    private CollectService collectService;

    @PostMapping("/addCollect")
    public ResultDTO<Boolean> addCollect(@RequestBody Collect collect){
        collect.setUid(TokenUtil.tokenExtractId(collect.getToken()));
        System.out.println(collect);
        return ResultDTO.success(collectService.save(collect));
    }

    @PostMapping("/deleteCollect")
    public ResultDTO<Boolean> deleteCollect(@RequestBody Collect collect){
        QueryWrapper<Collect> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("uid", TokenUtil.tokenExtractId(collect.getToken()));
        queryWrapper.eq("jid",collect.getJid());
        return ResultDTO.success(collectService.remove(queryWrapper));
    }
    @PostMapping("/getCollectByUid")
    public ResultDTO<Page<CollectDto>> getCollectByUid(@RequestBody Collect collect){
        return ResultDTO.success(collectService.getCollectByUid(collect));
    }

}
